package com.xgkj.diyiketang.activity.data;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xgkj.diyiketang.R;
import com.xgkj.diyiketang.data.MessageInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrater on 2015/12/28.
 */
public class SysMsgAdapter extends BaseAdapter {
    private Context mContext;
    private List<MessageInfo> mList = new ArrayList<MessageInfo>();

    public SysMsgAdapter(Context context) {
        mContext = context;
    }

    public void updateData(List<MessageInfo> list) {
        if (mList != null) {
            mList.addAll(list);
        }
        notifyDataSetChanged();
    }

    public void clearData() {
        if (mList != null) {
            mList.clear();
        }
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (mList != null) {
            return mList.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        if (mList != null) {
            return mList.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ChildHolder childHolder = null;
        if (convertView == null || convertView.getTag() == null) {
            childHolder = new ChildHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.sysmsg_item,null);
            childHolder.sysTitle = (TextView) convertView.findViewById(R.id.sys_item_title);
            childHolder.sysTime = (TextView) convertView.findViewById(R.id.sys_item_time);
           // childHolder.sysTip = (TextView) convertView.findViewById(R.id.sys_item_tip);
            convertView.setTag(childHolder);
        }else{
            childHolder = (ChildHolder) convertView.getTag();
        }

        MessageInfo msgInfo = mList.get(position);
        if(msgInfo!=null){
            childHolder.sysTitle.setText(msgInfo.getMsgTitle());
            childHolder.sysTime.setText(msgInfo.getMsgTime());
            //String tip = msgInfo.getMsgContent();
            //childHolder.sysTip.setText(Html.fromHtml(tip));
        }

        return convertView;
    }

        class ChildHolder {
            TextView sysTitle;
            TextView sysTime;
            //TextView sysTip;
        }
}